<!DOCTYPE html>
<html lang="zh">

<head>
  <th:block th:include="include :: header('基础管理')" />
  <th:block th:include="include :: layout-latest-css" />
  <th:block th:include="include :: ztree-css" />
  <style>
    .flex {
      display: flex;
    }
  </style>
</head>

<body class="gray-bg">
  <!-- <div class="ui-layout-west">
    <div class="box box-main">
      <div class="box-header">
        <div class="box-title"><i class="fa icon-grid"></i> 基础管理</div>
        <div class="box-tools pull-right">
          <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i
              class="fa fa-edit"></i></a>
          <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display: none">
            <i class="fa fa-chevron-up"></i>
          </button>
          <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠">
            <i class="fa fa-chevron-down"></i>
          </button>
          <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门">
            <i class="fa fa-refresh"></i>
          </button>
        </div>
      </div>
      <div class="ui-layout-content">
        <div id="tree" class="ztree"></div>
      </div>
    </div>
  </div> -->

  <div class="ui-layout-center">
    <div class="container-div">
      <div class="row">
        <div class="col-sm-12 search-collapse">
          <form id="user-form">
            <!-- <input type="hidden" id="equipmentId" name="equipmentId" /> -->
            <div class="select-list">
              <ul>
                <li style="display: flex;">
                  <label style="margin-right: 10px;width: 80px;">请选择机构:</label>
                  <select name="dev_azdw1_id" id="dev_azdw1_select1" class="first form-control azdw-select1"
                    data-index="1" style="width: 95px;"></select>
                </li>
                <li>
                  <select name="dev_azdw2_id" id="dev_azdw2_select1" class="second form-control azdw-select1"
                    data-index="2" style="width: 95px;"></select>
                </li>
                <li>
                  <select name="dev_azdw3_id" id="dev_azdw3_select1" class="third form-control azdw-select1"
                    data-index="3" style="width: 95px;"></select>
                </li>
                <li>
                  <select name="dev_azdw4_id" id="dev_azdw4_select1" class="fourth form-control azdw-select1"
                    data-index="4" style="width: 95px;"></select>
                </li>
                <li>
                  <select name="dev_azdw5_id" id="dev_azdw5_select1" class="fifth form-control azdw-select1"
                    data-index="5" style="width: 95px;"></select>
                </li>
                <li style="display: flex;">
                  <label>设备名称:</label>
                  <select name="equipmentId" id="point-select1" style="width:150px" class="form-control"></select>
                </li>
                <li>
                  监测点名称:<input type="text" name="pointName" id="pointName" style="width: 100px;"
                    placeholder="请输入监测点名称" />
                </li>
                <li>
                  <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                      class="fa fa-search"></i>&nbsp;搜索</a>
                  <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                      class="fa fa-refresh"></i>&nbsp;重置</a>
                </li>
              </ul>
            </div>
          </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
          <a class="btn btn-success" onclick="addBasics()" shiro:hasPermission="system:user:add">
            <i class="fa fa-plus"></i> 绑定点位
          </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
          <table id="bootstrap-table"></table>
        </div>
      </div>
    </div>
  </div>
  <!-- 新增监测点弹窗 -->
  <div class="modal" id="add-scene-dialog" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width: 650px;">
      <div class="modal-content animated flipInY">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
              class="sr-only">Close</span>
          </button>
          <h4 class="modal-title">新增监测点</h4>
        </div>

        <div class="modal-body">
          <!-- <div class="control-label"></div> -->
          <!-- 组织机构级联设备 -->
          <div class="input-wrap">
            <div class="flex">
              <label style="width: 81px;padding-top: 8px;text-align: center;">请选择机构:</label>
              <select name="dev_azdw1_id" id="dev_azdw1_select" class="first form-control azdw-select" data-index="1"
                style="width: 95px;"></select>
              <select name="dev_azdw2_id" id="dev_azdw2_select" class="second form-control azdw-select" data-index="2"
                style="width: 95px;margin-left: 10px;margin-right: 10px;"></select>
              <select name="dev_azdw3_id" id="dev_azdw3_select" class="third form-control azdw-select" data-index="3"
                style="width: 95px;"></select>
              <select name="dev_azdw4_id" id="dev_azdw4_select" class="fourth form-control azdw-select" data-index="4"
                style="width: 95px;margin-left: 10px;margin-right: 10px;"></select>
              <select name="dev_azdw5_id" id="dev_azdw5_select" class="fifth form-control azdw-select" data-index="5"
                style="width: 95px;"></select>
            </div>
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;margin-top: 10px;margin-bottom: 10px;">
            <label style="width: 78px;padding-top: 7px;text-align: center;">选择设备:</label>
            <input class="form-control" type="hidden" readonly="true" name="equipmentId" id="templateName2"
              maxlength="30" />
            <div class="item-wrap">
              <select name="equipment" id="point-select" style="width:200px" class="form-control"></select>
            </div>
          </div>

          <!-- 级联点位 -->
          <div class="input-wrap">
            <div class="flex">
              <label style="width: 520px;padding-top: 8px;text-align: center;">安装点位:</label>
              <select name="dev_azdw1_id" id="first" style="max-width:120px;margin-left: 4px;" class="first dw form-control m-b">
                <option value="">请选择</option>
              </select>
              <select name="dev_azdw2_id" id="second" style="max-width:120px;margin-left: 10px;margin-right: 10px;" class="second dw form-control m-b">
                <option value="">请选择</option>
              </select>
              <select name="dev_azdw3_id" id="third" style="max-width:120px" class="third dw form-control m-b">
                <option value="">请选择</option>
              </select>
              <select name="dev_azdw4_id" id="fourth" style="max-width:120px;margin-left: 10px;margin-right: 10px;" class="fourth dw form-control m-b">
                <option value="">请选择</option>
              </select>
              <select name="dev_azdw5_id" id="fifth" style="max-width:120px" class="fifth dw form-control m-b">
                <option value="">请选择</option>
              </select>
            </div>
          </div>
          <div class="input-wrap " style="display: flex;flex-direction: row;">
            <label style="width: 78px;padding-top: 7px;text-align: center;">监测点名称：</label>
            <select name="dev_azdw2_id" id="devName" style="max-width: 200px;" class="second form-control m-b">
              <option value="">请选择</option>
            </select>
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;margin-bottom: 5px;margin-top: 5px;">
            <label style="width: 78px;padding-top: 7px;text-align: center;">上限值：</label>
            <input class="form-control" type="number" name="maximum" id="scene1" value="" style="width: 200px;" />
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;">
            <label style="width: 78px;padding-top: 7px;text-align: center;">下限值：</label>
            <input class="form-control" type="number" name="minimum" id="scene2" value="" style="width: 200px" />
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
          <button type="button" class="btn btn-primary" onclick="submitAddScene()">保存</button>
        </div>
      </div>
    </div>
  </div>

  <!-- 修改监测点弹窗 -->
  <div class="modal" id="edit-scene-dialog" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content flipInY">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">
            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
          </button>
          <h4 class="modal-title">修改监测点</h4>
        </div>

        <div class="modal-body">
          <div class="input-wrap" style="display: flex;flex-direction: row;">
            <label style="width: 100px;padding-top: 8px;text-align: right;">监测点名称:</label>
            <input class="form-control" type="text" name="sceneName" id="add-scene-name" placeholder="请输入新的监测点名称"
              maxlength="30" />
            <input class="form-control" type="hidden" name="sceneName" id="hide-scene-name" placeholder="请输入新的监测点名称"
              maxlength="30" style="width: 200px" />
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;margin-top: 10px;">
            <label style="width: 82px;padding-top: 8px;text-align: right;">安装点位:</label>
            <input class="form-control" readonly="true" type="text" id="src-scene-name" style="width: 200px" value="" />
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;margin-top: 10px;">
            <label style="width: 82px;padding-top: 8px;text-align: right;">上限值:</label>
            <input class="form-control" type="number" id="editUp" value="" style="width: 200px" />
          </div>
          <div class="input-wrap" style="display: flex;flex-direction: row;margin-top: 10px;">
            <label style="width: 82px;padding-top: 8px;text-align: right;">下限值:</label>
            <input class="form-control" type="number" id="editLo" value="" style="width: 200px" />
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-white" data-dismiss="modal">
              关闭
            </button>
            <button type="button" class="btn btn-primary" onclick="submitEditScene()">
              保存
            </button>
          </div>
        </div>
      </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
      // var editFlag = [[${@permission.hasPermi('youtianNew:basicsMangement:edit')}]];
      // var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
      // var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
      var treeClick = null
      var obj = {};
      $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
          panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
          var opt = {
            win: $('.ui-layout-center'),
            doc: $('.ui-layout-center')
          };
          $('#scroll-up').toTop(opt);
        }
        queryUserList();
        queryDeptTree();
        initfirst(1)
        initAZDWselect();
        initAZDWselect1()
        $('.azdw-select').change(function (e) {
          var getSelectIndex = $(this).attr("data-index") || 1;
          var maxSelectIndex = 6;
          var nextSelectIndex = Number(getSelectIndex) + 1;
          let startIndex = getSelectIndex;
          while (startIndex < maxSelectIndex) {
            startIndex++;
            $(`#dev_azdw${startIndex}_select`).val("").text("请选择")
          }
          // 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
          if (nextSelectIndex < maxSelectIndex) {
            initAZDWselect(nextSelectIndex);
          }
          // 调用根据条件筛选监测点
          queryPointSelect();
        })
        $('.azdw-select1').change(function (e) {
          var getSelectIndex = $(this).attr("data-index") || 1;
          var maxSelectIndex = 6;
          var nextSelectIndex = Number(getSelectIndex) + 1;
          let startIndex = getSelectIndex;
          while (startIndex < maxSelectIndex) {
            startIndex++;
            $(`#dev_azdw${startIndex}_select1`).val("").text("请选择")
            $('#equipmentId').val($(this).val())
          }
          // 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
          if (nextSelectIndex < maxSelectIndex) {
            initAZDWselect1(nextSelectIndex);
          }
          // 调用根据条件筛选监测点
          queryPointSelect1();
        })
      });

      //新增弹框中的组织机构
      function queryPointSelect() {
        $("#point-select").html(`<option value="">请选择</option>`);
        let data = {
          dw_5_id: $("#dev_azdw5_select").val()
        };
        console.log(data, "data");
        $.ajax({
          method: "POST",
          url: "/gzmx_tag/gzmx_tag/dev_name",
          contentType: "application/json",
          dataType: 'json',
          data: JSON.stringify(data),
          success: function (res) {
            console.log(res, "data res");
            var optionHTML = `<option value="">请选择</option>`;
            for (let i = 0; i < res.data.length; i++) {
              var item = res.data[i];
              optionHTML += `<option value="${item.id}"  >${item.dev_name}</option>`
            }
            $("#point-select").html(optionHTML);
            $("#upperLimit").val("")
            $("#lowerLimit").val("")
          }
        });
      }
      function initAZDWselect(nextSelectIndex) {
        var params = {
          "jb": 1
        }
        nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
        var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select`);
        if (nextSelectIndex > 1) {
          params = {
            fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select`).val()
          }
        }
        $.ajax({
          type: "post",
          url: "/gzmx_scdw/gzmx_scdw/list",
          data: params,
          success: function (res) {
            console.log(' 生产点位 /gzmx_scdw/gzmx_scdw/list res');
            console.log(res);
            console.log($nextSelect);
            var optionHTML = `<option value="">请选择</option>`
            for (let i = 0; i < res.length; i++) {
              optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
            }
            $nextSelect.html(optionHTML);
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }

      //搜索
      function initAZDWselect1(nextSelectIndex) {
        var params = {
          "jb": 1
        }
        nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
        var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select1`);
        if (nextSelectIndex > 1) {
          params = {
            fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select1`).val()
          }
        }
        $.ajax({
          type: "post",
          url: "/gzmx_scdw/gzmx_scdw/list",
          data: params,
          success: function (res) {
            console.log(' 生产点位 /gzmx_scdw/gzmx_scdw/list res');
            console.log(res);
            console.log($nextSelect);
            var optionHTML = `<option value="">请选择</option>`
            for (let i = 0; i < res.length; i++) {
              optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
            }
            $nextSelect.html(optionHTML);
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }

      function queryPointSelect1() {
        $("#point-select1").html(`<option value="">请选择</option>`);
        let data = {
          dw_5_id: $("#dev_azdw5_select1").val()
        };
        console.log(data, "data");
        $.ajax({
          method: "POST",
          url: "/gzmx_tag/gzmx_tag/dev_name",
          contentType: "application/json",
          dataType: 'json',
          data: JSON.stringify(data),
          success: function (res) {
            console.log(res, "data res");
            var optionHTML = `<option value="">请选择</option>`;
            for (let i = 0; i < res.data.length; i++) {
              var item = res.data[i];
              optionHTML += `<option value="${item.id}"  >${item.dev_name}</option>`
            }
            $("#point-select1").html(optionHTML);
            $("#upperLimit").val("")
            $("#lowerLimit").val("")
          }
        });
      }

      function queryUserList() {
        var options = {
          url: '/youtian/workspace-category/getDevicePointList',
          modalName: "用户",
          // showSearch: false,
          columns: [{
            checkbox: true,
            align: 'center'
          },
          {
            field: 'dev_azdw1_name',
            title: '组织机构',
            align: 'center'
          },
          {
            field: 'equipmentName',
            title: '设备名称',
            align: 'center'
          },
          {
            field: 'pointId',
            title: '点位ID',
            align: 'center'
          },
          {
            field: 'pointName',
            title: '监测点名称',
            // sortable: true,
            align: 'center'
          },
          {
            field: 'upperLimit',
            title: '上限值',
            align: 'center'
          },
          {
            field: 'lowerLimit',
            title: '下限值',
            align: 'center'
          },
          {
            title: '操作',
            align: 'center',
            formatter: function (value, row, index) {
              console.log(value, row, index, '操作');
              let editRow = JSON.stringify(row)
              var actions = [];
              actions.push(`<a class='btn btn-primary btn-xs' onclick='editBasics(${editRow})'><i class='fa fa-edit'></i>编辑</a>`);
              actions.push(`<a class='btn btn-danger btn-xs' style="margin-left: 10px;" onclick='removeBtn(${row.pointEquipmentId})'><i class="fa fa-remove"></i>解绑</a>`);
              return actions.join('')
            }
          }]
        };
        console.log(options.url, 'optionsurl');
        console.log(options);
        $.table.init(options);
      }

      // 表格新增按钮
      function addBasics(row) {
        $('#devName').val(''),
          $('[name=maximum]').val(''),
          $('[name=minimum]').val('')
        if (treeClick) {
          let value = treeClick.name
          $('[name=equipment]').val(value)
        }
        $('#add-scene-dialog').modal('show');
      }


      // 表格新增弹窗保存方法
      function submitAddScene() {
        let id = $('#point-select').val()
        if (!id) {
          return $.modal.alertWarning("未选取设备，请核对");
        }
        // else if(treeClick.level != 5) {
        //   return $.modal.alertWarning("请在场景下绑定点位");
        // }

        // var idStr = treeClick.id
        // var getDeviceId = '';
        // if (idStr) {
        //   var idArr = idStr.toString().split('1000000');
        //   getDeviceId = idArr[idArr.length - 1];
        // }
        let data = {
          // equipmentId: treeClick.id,
          equipmentId: $('#point-select').val(),
          pointId: $('#devName').val(),
          maximum: $('[name=maximum]').val(),
          minimum: $('[name=minimum]').val()
        }
        console.log(data, '--------------');
        // if (!data.pointId || !data.maximum || !data.minimum) {
        //   return $.modal.alertWarning("必填项不能为空");
        // }

        // if (parseInt(data.maximum) <= parseInt(data.minimum)) {
        //   return $.modal.alertWarning("上限值不能小于下限值");
        // }
        $.ajax({
          method: 'post',
          url: '/youtian/point-equipment',
          data: JSON.stringify(data),
          dataType: "json",
          contentType: 'application/json',
          success: function (res) {
            console.log(res, '绑定点位提交');
            if (res.code === 0) {
              $.modal.msgSuccess("操作成功");
              $('#add-scene-dialog').modal('hide')
              $('#dev_azdw1_select').val('请选择')
              $('#dev_azdw2_select').val('')
              $('#dev_azdw3_select').val('')
              $('#dev_azdw4_select').val('')
              $('#dev_azdw5_select').val('')
              $('#scene1').val('')
              $('#scene2').val('')
              $('#templateName2').val('')
              $('#first').val('请选择')
              $('#second').val('')
              $('#third').val('')
              $('#fourth').val('')
              $('#fifth').val('')
              $('#point-select').val('请选择')
              $.table.refresh();
            } else {
              $.modal.msgError("操作失败", res.msg);
            }
          }
        })
      }

      // 新增弹框监测点名称
      function selectClick(obj) {
        let data = {
          parentId: obj.parentId,
          type: obj.type
        };
        $.ajax({
          method: "get",
          // url: "/gzmx_tag/gzmx_tag/unboundDeviceTaglist",
          url: "/gzmx_scdw/gzmx_scdw/sourcelist",
          data: data,
          success: function (result) {
            console.log(result, 'result');
            var rows = result.length;
            var html = `<option value="">请选择</option>`
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#devName").html(html);
            $('#devName').change(function () {
              var dianwei;
              //先循环返回的数据然后过滤出想同的数据
              console.log($('#devName').val(),'----->');
              // for (let i = 0; i < result.length-1; i++) {
              //   dianwei = result.filter(item => {
              //     return item.id == $('#devName').val()
              //   })
              // }
              dianwei = result.filter(item=>{
                console.log(item,'----->12');
                return item.id == $('#devName').val()
              })
              console.log(dianwei,'------>');
              $('#scene1').val(dianwei[0].max)
              $('#scene2').val(dianwei[0].min)
            })
          }
        });
      }
      function initfirst(objDivId) {
        $.ajax({
          method: "get",
          url: '/gzmx_scdw/gzmx_scdw/sourceLevelist',
          data: { type: objDivId },
          success: function (result) {
            console.log(result, 'res');
            var rows = result.length;
            var html = `<option value="">请选择</option>`
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#first").html(html);
            $("#first").change(function () {
              $("#dev_azdw1_name").val($(this).find('option:selected').text());
              initsecond($("#first").val());
              obj = {
                parentId: $('#first').val(),
                type: 1
              }
              selectClick(obj)
            });
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }
      function initsecond(objDivId) {
        $.ajax({
          type: "get",
          url: '/gzmx_scdw/gzmx_scdw/sourceLevelist',
          data: {
            type: 2,
            parentId: objDivId,
          },
          success: function (result) {
            var rows = result.length;
            var html = `<option value="">请选择</option>`;
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#second").html(html);
            $("#second").change(function () {
              initthird($("#second").val());
              $("#dev_azdw2_name").val($(this).find('option:selected').text());
              obj = {
                parentId: $('#second').val(),
                type: 2
              }
              selectClick(obj)
            });
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }
      function initthird(objDivId) {
        $.ajax({
          type: "get",
          url: '/gzmx_scdw/gzmx_scdw/sourceLevelist',
          data: {
            type: 3,
            parentId: objDivId,
          },
          success: function (result) {
            //alert(JSON.stringify(result.length));

            var rows = result.length;
            //alert(rows);
            var html = `<option value="">请选择</option>`
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#third").html(html);
            $("#third").change(function () {
              initfourth($("#third").val());
              $("#dev_azdw3_name").val($(this).find('option:selected').text());
              //	$provinceHid.val($provinceSelect.find("option:selected").text());
              //	provenceChange(objDivId);
              obj = {
                parentId: $('#third').val(),
                type: 3
              }
              selectClick(obj)
            });
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }
      function initfourth(objDivId) {
        $.ajax({
          type: "get",
          url: '/gzmx_scdw/gzmx_scdw/sourceLevelist',
          data: {
            type: 4,
            parentId: objDivId,
          },
          success: function (result) {
            var html = `<option value="">请选择</option>`
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#fourth").html(html);
            $("#fourth").change(function () {
              initfifth($("#fourth").val());
              $("#dev_azdw4_name").val($(this).find('option:selected').text());
              obj = {
                parentId: $('#fourth').val(),
                type: 4
              }
              selectClick(obj)
            });
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }
      function initfifth(objDivId) {
        $.ajax({
          type: "get",
          url: '/gzmx_scdw/gzmx_scdw/sourceLevelist',
          data: {
            type: 5,
            parentId: objDivId,
          },
          success: function (result) {
            //alert(JSON.stringify(result.length));

            var rows = result.length;
            //alert(rows);
            var html = `<option value="">请选择</option>`
            for (let i = 0; i < result.length; i++) {
              html += `<option value="` + result[i].id + `">` + result[i].name + `</option>`
            }
            $("#fifth").html(html);
            $("#fifth").change(function () {
              $("#dev_azdw5_name").val($(this).find('option:selected').text());
              obj = {
                parentId: $('#fifth').val(),
                type: 5
              }
              selectClick(obj)
            });
          },
          error: function (error) {
            $.modal.alertWarning(error);
          }
        });
      }

      // 表格编辑按钮
      function editBasics(row) {
        console.log(row, 'editrow');
        console.log(treeClick, 'treeClick');
        $('#add-scene-name').val(row.pointName)
        $('#src-scene-name').val(row.equipmentName)
        $('#hide-scene-name').val(row.pointId), $('#editUp').val(row.upperLimit)
        $('#editLo').val(row.lowerLimit)
        $('#edit-scene-dialog').modal('show');
      }

      // 表格编辑弹窗保存按钮
      function submitEditScene() {
        let data = {
          pointId: $('#hide-scene-name').val(),
          upperLimit: $('#editUp').val(),
          lowerLimit: $('#editLo').val()
        }
        if (parseInt(data.upperLimit) <= parseInt(data.lowerLimit)) {
          return $.modal.alertWarning("上限值不能小于下限值");
        }
        $.ajax({
          method: 'put',
          url: '/youtian/pointAttribute/edit',
          data: JSON.stringify(data),
          dataType: "json",
          contentType: 'application/json',
          success: function (res) {
            if (res.code == 0) {
              $.modal.msgSuccess("操作成功");
              $('#edit-scene-dialog').modal('hide')
              $.table.search();
            } else {
              $.modal.msgError("操作失败", res.msg);
            }
          }
        })
      }

      // 表格删除按钮
      function removeBtn(row) {
        console.log(123);
        let content = '是否解绑'
        $.modal.confirm(content, function (index) {
          console.log(123);
          $.ajax({
            method: 'delete',
            url: `/youtian/point-equipment/${row}`,
            dataType: "json",
            headers: { "Content-Type": "application/json" },
            success: function (res) {
              console.log(res);
              if (res.code == 0) {
                $.modal.msgSuccess('解绑成功');
              } else {
                $.modal.alertError('解绑失败');
              }
              $.table.refresh()
            }
          })
        })
      }

      // 渲染左侧树
      function queryDeptTree() {
        var options = {
          url: '/gzmx_scdw/gzmx_scdw/jichuTreeDataNew',
          expandLevel: 2,
          onClick: zOnClick
        };
        let ab = $.tree.init(options);
      }
      function zOnClick(event, treeId, treeNode) {
        console.log(event, 'event');
        console.log(treeId, treeNode, 'treeNode');
        treeClick = treeNode
        // $("#deptId").val(treeNode.id);
        var idStr = treeNode.id
        var getDeviceId = '';
        if (idStr && treeNode.label == "device") {
          var idArr = idStr.toString().split('1000000');
          getDeviceId = idArr[idArr.length - 1] || idStr;
        }
        $("#equipmentId").val(getDeviceId);
        $.table.search();
      }



      $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
      });

      $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
      });

      $('#btnRefresh').click(function () {
        queryDeptTree();
      });


    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
    	<div class="col-xs-offset-1">
    		<input type="file" id="file" name="file"/>
    		<div class="mt10 pt5">
    			<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
    			 &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
    		</div>
    		<font color="red" class="pull-left mt10">
    			提示：仅允许导入“xls”或“xlsx”格式文件！
    		</font>
    	</div>
    </form>
  </script>

</html>